<template>
    <div
        class="dialog-box-contaner"
        @click.self="showDialog = false"
        v-if="showDialog"
      >
        <div class="dialog-box">
          <div class="dialog-body">
            <div class="body-title">温馨提示</div>
            <div class="body-content">{{content}}</div>
          </div>
          <div class="dialog-bottom">
            <div class="btn-cancel cursor-pointer" @click="cancel" v-if="showCancel">取消</div>
            <div class="btn-confirm cursor-pointer" @click="confirm">确认</div>
          </div>
        </div>
      </div>
</template>

<script setup>
import { ref } from 'vue';
const showDialog = ref(false)
const showCancel  = ref(false)
const content = ref('')

let callBack = ()=>{}
const showAlert = (msg,hasCancel,confirmCall)=>{
    content.value = msg
    showCancel.value = hasCancel
    showDialog.value = true
    callBack = confirmCall
}

const cancel = ()=>{
    showDialog.value = false
    return 'cancel'
}
const confirm = ()=>{
    showDialog.value = false
    if(callBack){
        callBack()
    }
    return 'confirm'
}

defineExpose({
    showAlert,
    cancel,
    confirm
})
</script>

<style  scoped>
.dialog-box-contaner {
      position: absolute;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      background-color: rgba(0, 0, 0, 0.7);
    }
    .dialog-box {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 57.9vw;
      height: 32.03vw;
      border-radius: 20px;
      background-color: #fff;
    }
    .dialog-body {
      padding: 5.07vw;
    }
    .body-title {
      font-size: 3.613vw;
      font-weight: bolder;
    }
    .body-content {
      margin-top: 2.441vw;
      font-size: 2.637vw;
    }
    .dialog-bottom {
      position: absolute;
      bottom: 5.27vw;
      left: 0;
      width: 100%;
      display: flex;
      justify-content: center;
    }
    .dialog-bottom > div {
      width: 23.83vw;
      height: 7.03vw;
      font-size: 2.93vw;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 300px;
    }
    .btn-cancel {
      margin-right: 2.246vw;
      background-color: #d8ddd6;
      color: #000;
    }
    .btn-confirm {
      color: #fff;
      background: linear-gradient(
        to right,
        rgb(150, 150, 249),
        rgb(105, 105, 252)
      );
    }
</style>